<?php
$link = mysql_connect("localhost", "root", "U2Fa555AnY9EWzKP");
mysql_query("create database if not exists `QingZhi` character set 'utf8' collate 'utf8_general_ci'");
mysql_select_db("QingZhi", $link);

mysql_query("create table if not exists article (id int(100) primary key auto_increment,title text,author text,imgurl text,content text,time varchar(100)) default charset=utf8", $link);
mysql_query("set names utf8");
if($_POST){
	$time=time();
	$result=mysql_query("INSERT INTO `article`(`title`, `author`, `imgurl`, `content`, `time`) VALUES ('{$_POST['title']}','{$_POST['username']}','{$_POST['imgurl']}','{$_POST['content']}','{$time}')");
	echo "添加成功";
};
if(@$_GET['act']&&$_GET['act']=="getinfo"){
	$arr=Array();
	$result=mysql_query("SELECT `id`, `title`, `author`, `imgurl`, `content`, `time` FROM `article`");
	while($row=mysql_fetch_assoc($result)){
		$row['time']=date('Y-m-d',$row['time']); 
		$arr[]=$row;
		
	}
	echo json_encode(Array("model"=>$arr));
};
if(@$_GET['id']){
	$result=mysql_query("SELECT `id`, `title`, `author`, `imgurl`, `content`, `time` FROM `article` where id='{$_GET['id']}'");
        $row=mysql_fetch_assoc($result);
		$row['time']=date('Y-m-d',$row['time']); 
	echo json_encode(Array("data"=>$row));
};
	?>